<html>
<body>
<form action="http://127.0.0.1:8081/process_get" method="POST">
    First Name: <input type="text" name="first_name">  <br>

    Last Name: <input type="text" name="last_name">
    <input type="submit" value="Submit">
</form>
<h3>文件上传：</h3>
选择一个文件上传: <br />
<form action="/file_upload" method="post" enctype="multipart/form-data">
    <input id="selectFile" type="file" name="image" size="50" />
</form>
</body>
<script>
    var selectFile = document.getElementById("selectFile");
    selectFile.onchange = function upload(){
        var files = !!this.files ? this.files : [];
        if (!files.length || !window.FileReader) {
            console.log("浏览器不支持HTML5");
            return false;
        };
        // 创建一个FormData对象,用来组装一组用 XMLHttpRequest发送请求的键/值对
        var fd = new FormData();
        // 把 input 标签获取的文件加入 FromData 中
        fd.append('file', files[0]);

        // Ajax
        var request = new XMLHttpRequest();
        request.open("POST", "http://127.0.0.1:8081/file_upload");
        request.send(fd);
        request.onreadystatechange = function(){
            if(request.readyState === 4 & request.status === 200){
                console.log("上传成功");
                var response = JSON.parse(request.responseText);
                console.log(response);
            }
        }
    }
</script>
</html>